from flask.sessions import SecureCookieSessionInterface
from flask.sessions import SecureCookieSession, NullSession


class CustomSecureCookieSessionInterface(SecureCookieSessionInterface):
    session_class = SecureCookieSession
    null_session_class = NullSession

    def save_session(self, app, session, response):
        """
            因前端要求，为适应当前（不良）设计，改写了flask原生的session机制：
            只在/authorization /hackroute和/logout三个接口，进行save_session动作

        :param app:
        :param session:
        :param response:
        :return:
        """
        if session.accessed is not False:
            return
        else:
            SecureCookieSessionInterface.save_session(self, app, session, response)
